package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVoRedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 将redis中数据进行持久化
 */
//@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVoRedisService statisVoRedisService;

    @Autowired
    private IStrategyService strategyService;


    //@Scheduled定时任务标签
    //cron指定任务计划：什么时候执行doWork方法，周期是多少
    //定时任务时间间隔：没有标准，redis数据量决定,如果数据量较大,时间周期适当缩短。
    @Scheduled(cron = "0/15 * * * * ? ")
    public void doWork(){
        System.out.println("----------------vo持久化-strat----------------------");
        //获取所有的攻略vo数据
        List<StrategyStatisVO> vos = statisVoRedisService.queryStrategyVos();

        //更新vo对应的攻略
        for (StrategyStatisVO vo : vos) {
            strategyService.updateStatisVo(vo);
        }
        System.out.println("----------------vo持久化-end------------------------");
    }
}
